package com.ydgk.dao;

import com.ydgk.bean.Book;
import org.springframework.jdbc.core.BeanPropertyRowMapper;

import java.util.List;

public class BookDao extends BaseDao<Book> {
    @Override
    public int save(Book book) {
        return 0;
    }

    @Override
    public int updateById(Book book) {
        return 0;
    }

    @Override
    public int deleteById(int id) {
        return this.template.update("delete from book where bid = ?" , id);
    }

    @Override
    public List<Book> findAll() {
        return this.template.query("select * from book" ,new BeanPropertyRowMapper<>(Book.class));
    }

    @Override
    public Book findById(int id) {
        return null;
    }

    @Override
    public List<Book> paging(int pageNumber) {
        return this.template.query("select * from book order by bid desc limit ?,?",new BeanPropertyRowMapper<>(Book.class),(pageNumber-1)*pageCount,pageCount);
    }

    public List<Book> findByFkId(int sid){
        return this.template.query("select * from book where sid = ?" ,new BeanPropertyRowMapper<>(Book.class),sid);
    }
    //图片表中有多少条数据
    public int total(){
        return this.template.queryForObject("select count(*) from book",Integer.class);
    }
}
